package com.cliff.joinme;

import org.cybergarage.upnp.event.EventListener;

import com.cliff.joinme.toolkit.ControlPointManager;

import android.os.Handler;
import android.os.Message;

public class PlayHandler extends Handler implements EventListener{

	PlayBaseActivity mActivity = null;
	public enum PLAY_STATE {INITIALIZING, READY, PLAYING, INPUT, NOT_CONTROLABLE};
	protected PLAY_STATE mState = PLAY_STATE.INITIALIZING;
	
	public static final int MESSAGE_INIT = 1;
	public static final int MESSAGE_UNINIT = 2;
	public static final int MESSAGE_PLAY = 10;
	
	public PlayHandler(PlayBaseActivity activity) {
		mActivity = activity;
	}
	
	@Override
	public void handleMessage(Message msg) {
		// TODO Auto-generated method stub
		switch(msg.what) {
		case MESSAGE_INIT:
			init();
			break;
		case MESSAGE_UNINIT:
			uninit();
			break;
		}
		super.handleMessage(msg);
	}
	
	protected void init() {
		//subscribe
		if (ControlPointManager.getInstance().subscribeCurrentRenderer(this)) {
			mState = PLAY_STATE.NOT_CONTROLABLE;
		}
		else {
			mState = PLAY_STATE.READY;			
		}
		
		//set interface
	}

	protected void uninit() {
		//unsubscribe
		ControlPointManager.getInstance().unsubscribeCurrentRenderer(this);
		
		//set state INITIALIZING
		mState = PLAY_STATE.INITIALIZING;			
	}

	@Override
	public void eventNotifyReceived(String uuid, long seq, String varName,
			String value) {
		//send message to self
		System.out.println("uuid="+uuid+";seq="+seq+";varName="+varName+";value="+value);
	}
	
}
